package net.joint_painting.client.view;

import net.joint_painting.client.observer.ViewObject;
import net.joint_painting.client.observer.ViewObserverListener;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author CAM
 * @version $Revision: 1.0 $
 */
public class Navigation extends Composite {

    /**
     * @author CAM
     * @version $Revision: 1.0 $
     */
    interface NavigationUiBinder extends UiBinder<Widget, Navigation> {
    }

    private static NavigationUiBinder uiBinder = GWT
	    .create(NavigationUiBinder.class);
    @UiField
    PushButton upButton;
    @UiField
    PushButton rightButton;
    @UiField
    PushButton downButton;

    @UiField
    PushButton leftButton;

    private ViewObserverListener viewObserverListener;

    public Navigation() {
	initWidget(uiBinder.createAndBindUi(this));
    }

    /**
     * Method addViewObserver.
     * 
     * @param viewObserverListener
     *            ViewObserverListener
     */
    public void addViewObserver(ViewObserverListener viewObserverListener) {
	this.viewObserverListener = viewObserverListener;
    }

    /**
     * Method onDownButtonClick.
     * 
     * @param event
     *            ClickEvent
     */
    @UiHandler("downButton")
    void onDownButtonClick(ClickEvent event) {
	viewObserverListener.notify(new ViewObject(this,
		ViewObject.ViewObjectType.MOVEDOWN));
    }

    /**
     * Method onLeftButtonClick.
     * 
     * @param event
     *            ClickEvent
     */
    @UiHandler("leftButton")
    void onLeftButtonClick(ClickEvent event) {
	viewObserverListener.notify(new ViewObject(this,
		ViewObject.ViewObjectType.MOVELEFT));
    }

    /**
     * Method onRightButtonClick.
     * 
     * @param event
     *            ClickEvent
     */
    @UiHandler("rightButton")
    void onRightButtonClick(ClickEvent event) {
	viewObserverListener.notify(new ViewObject(this,
		ViewObject.ViewObjectType.MOVERIGHT));
    }

    /**
     * Method onUpButtonClick.
     * 
     * @param event
     *            ClickEvent
     */
    @UiHandler("upButton")
    void onUpButtonClick(ClickEvent event) {
	viewObserverListener.notify(new ViewObject(this,
		ViewObject.ViewObjectType.MOVEUP));
    }
}
